//ConsistentComposite类
package cn.edu.scau.cmi.yangzhichao.composite.consistent;

import java.util.ArrayList;
import java.util.List;

public class ConsistentComposite extends ConsistentComponent{
    private List<ConsistentComponent> children=new ArrayList<>();
    public ConsistentComposite(String name) {
        super(name);
    }
    public void addChild(ConsistentComponent consistentComponent){
        children.add(consistentComponent);
    }
    public void deleteChild(int index){
        children.remove(index);
    }
    public void updateChild(ConsistentComponent safeComponent,int index){
        children.set(index,safeComponent);
    }
    @Override
    public void display(int level) {
        for(int i=0;i<level;i++){
            ConsistentCompositeViewController.addToTextView("-");
        }
        ConsistentCompositeViewController.addToTextView(name+"\r\n");
        for(int i=0;i<children.size();i++){
            children.get(i).display(level+2);
        }
    }
    public List getChildren(){
        return children;
    }

}
